﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TCHSHue.BLL;

namespace TCHSHue.Modules.AdminControl.User
{
    public partial class ctrUserList : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var user = (DAL.User)Session["userDangNhap"];
            if (user != null)
            {
                if (user.quyen != ((int)Quyen.Admin).ToString())
                {
                    Response.Redirect("Admin.aspx");
                }
            }
            NapDanhSachUser();
        }
        private void NapDanhSachUser()
        {
            var ls = UserBLL.getList();
            gridUser.DataSource = ls;
            gridUser.DataBind();
        }

        //protected void RedirectEdit(object sender, CommandEventArgs e)
        //{
        //    Response.Redirect("~/Modules/Admin.aspx?mode=chinhlk&id=" + e.CommandArgument.ToString());
        //}

        protected void Delete(object sender, CommandEventArgs e)
        {
            var user = (DAL.User)Session["userDangNhap"];
            if (user.tenDangNhap == e.CommandArgument.ToString())
            {
                Page.RegisterClientScriptBlock("XoaUser", "<SCRIPT Language='JavaScript'> alert('Không thể xóa user này'); </SCRIPT>");
                return;
            }
            if (!UserBLL.delete(e.CommandArgument.ToString()))
                Page.RegisterClientScriptBlock("XoaUser", "<SCRIPT Language='JavaScript'> alert('Không thể xóa user này'); </SCRIPT>");
            else
                NapDanhSachUser();
        }
    }
}